<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>父组件向子组件传递数据</title>
</head>
<body>
<div id="app">
    <!--绑定的对象为子组件接收的变量，绑定的值为父组件中的变量-->
    <cpn v-bind:info="info" v-bind:movies="movies" v-bind:num="number"></cpn>
</div>

<template id="cpn">
    <h1>这是一个自定义组件</h1>
    <h2>来自父组件的数据：{{ info }}</h2>
    <h2>来自父组件的数据并全部转换为大写：{{ capital_info }}</h2>

    <ul>
        <li v-for="item in movies">{{ item }}</li>
    </ul>

</template>

<script type="module">
    import {createApp, ref, defineComponent} from "../../../js/vue.esm-browser.js";

    let component = defineComponent(
        {
            template: "#cpn",
            // 通过 props 选项来接收数据
            props: ['info', 'movies', 'num'],
            // setup 函数的第一个参数用来接收外部传入的值用于后续的处理。
            setup(props) {
                console.log(props);

                // 获取模板变量的值，并转换为大写
                let capital_info = ref(props.info).value.toUpperCase()

                console.log(typeof props.num);

                return {
                    capital_info,
                }
            }
        }
    );

    let app = createApp(
        {
            setup() {
                let info = ref("Hello, Vue!")
                let movies = ref(['霸王级别', '夜半歌声', '纵横四海'])
                let number = ref(0)
                return {
                    info, movies, number,
                }
            }
        }
    );

    app.component("cpn", component)
    app.mount("#app")
</script>
</body>
</html>